using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using AntEater.ComponentModel;

namespace AntEater.Runtime.UI
{
    /// <summary>
    /// View for editing a single External Build Property.
    /// </summary>
    internal partial class ExternalBuildPropertyView : Form
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="ExternalBuildPropertyView"/> class.
        /// </summary>
        public ExternalBuildPropertyView() {
            InitializeComponent();
        }

        private ExternalBuildProperty _externalBuildProperty;

        /// <summary>
        /// Gets the external build property.
        /// </summary>
        /// <value>The external build property.</value>
        public ExternalBuildProperty ExternalBuildProperty {
            get { return _externalBuildProperty; }
            set { _externalBuildProperty = value; }
        }

        /// <summary>
        /// Oks the clicked.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void OkClicked(object sender, EventArgs e) {
            _externalBuildProperty = new ExternalBuildProperty();
            _externalBuildProperty.Name = nameTextBox.Text;
            _externalBuildProperty.Value = valueTextBox.Text;
            
            this.DialogResult = DialogResult.OK;
            
            this.Close();
        }

        /// <summary>
        /// Cancels the clicked.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void CancelClicked(object sender, EventArgs e) {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        /// <summary>
        /// Forces the control to invalidate its client area and immediately redraw itself and any child controls.
        /// </summary>
        /// <PermissionSet><IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/><IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/><IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence"/><IPermission class="System.Diagnostics.PerformanceCounterPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/></PermissionSet>
        public override void Refresh() {

            if (this.ExternalBuildProperty != null) {
                nameTextBox.Text = this.ExternalBuildProperty.Name;
                valueTextBox.Text = this.ExternalBuildProperty.Value;
            }

            base.Refresh();
        }

        /// <summary>
        /// Names the or value changed.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void NameOrValueChanged(object sender, EventArgs e) {
            okButton.Enabled = (!string.IsNullOrEmpty(nameTextBox.Text) && !string.IsNullOrEmpty(valueTextBox.Text));
        }

    }
}